package com.stockz.equity.charting.display.indicator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.stockz.equity.charting.painter.indicator.LineIndicatorPainter;
import com.stockz.equity.charting.util.Constant.OVERLAY;
import com.stockz.equity.indicator.Indicator;
import com.stockz.equity.indicator.movingAverage.simple.SimpleMovingAverageIndicator;
import com.stockz.equity.indicator.movingAverage.simple.SimpleMovingAverageIndicatorConfiguration;
import com.stockz.equity.model.Bar.BarValueType;

@Component
@Lazy
@Scope("prototype")
public class SimpleMovingAverageIndicatorDisplay extends AbstractDisplayableIndicatorConfiguration {

	@Autowired private SimpleMovingAverageIndicator simpleMovingAverageIndicator;
	private String fullName = "Simple Moving Average";
	private String shortName = "SMA";
	
	@Override
	public Indicator<SimpleMovingAverageIndicatorConfiguration> getIndicator() {
		return simpleMovingAverageIndicator;
	}
	
	@Override
	public BarValueType getBarValueType() {
		return simpleMovingAverageIndicator.getBarValueType();
	}
	
	@Override
	public void setBarValueType(BarValueType barValueType) {
		simpleMovingAverageIndicator.setBarValueType(barValueType);
	}
	
	@Override
	public Object getConfiguration() {
		return simpleMovingAverageIndicator.getIndicatorConfiguration();
	}
	
	@Override
	public Class<LineIndicatorPainter> getPainterClass() {
		return LineIndicatorPainter.class;
	}
	
	@Override
	public String getDescription() {
		return getShortName()+","+simpleMovingAverageIndicator.getIndicatorConfiguration().getSpan()
		+","+simpleMovingAverageIndicator.getBarValueType();
	}
	
	@Override
	public OVERLAY getOverlay() {
		BarValueType barValueType = simpleMovingAverageIndicator.getBarValueType();
		if(BarValueType.VOLUME.equals(barValueType)){
			return OVERLAY.VOLUME;
		}else if(BarValueType.AVGTRADEPRICE.equals(barValueType)
				|| BarValueType.AVGTRADESIZE.equals(barValueType)
				|| BarValueType.TRADES.equals(barValueType)
				|| BarValueType.TURNOVER.equals(barValueType)
				|| BarValueType.SPREAD.equals(barValueType)
				|| BarValueType.ACTIVITY.equals(barValueType)
				|| BarValueType.CRUNCH.equals(barValueType)){
			return OVERLAY.INDEPENDENT;
		}else{
			return OVERLAY.PRICE;
		}
	}

	@Override
	public boolean isOverlappable() {
		return true;
	}
	
	@Override
	public String getFullName() {
		return fullName;
	}

	@Override
	public String getShortName() {
		return shortName;
	}
}